/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.sql.Array;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

/**
 * <p>Project: javase - LinkedList2
 * <p>Powered by webrx On 2021-12-09 15:51:13
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class LinkedList2 {
    public static void main(String[] args) {
        var list1 = a1();
        long a = System.currentTimeMillis();
        System.out.println(list1.get(300000));
        long b = System.currentTimeMillis();
        System.out.println(b - a);
        System.out.println("-------------");
        var list2 = a2();
        a = System.currentTimeMillis();
        System.out.println(list2.get(300000));
        b = System.currentTimeMillis();
        System.out.println(b - a);
    }

    public static List<String> a2() {
        //System.out.println(str());
        long start = System.currentTimeMillis();
        var list = new LinkedList<String>();
        for (int i = 0; i < 300000; i++) {
            list.add(0, str());
        }
        list.add("javaa1");
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        return list;

    }

    public static ArrayList<String> a1() {
        //System.out.println(str());
        long start = System.currentTimeMillis();
        var list = new ArrayList<String>();
        for (int i = 0; i < 300000; i++) {
            list.add(0, str());
        }
        list.add("javaa1");
        long end = System.currentTimeMillis();
        System.out.println(end - start);
        return list;

    }

    public static String str() {
        String letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        StringBuilder sbu = new StringBuilder();
        Random rand = new Random();
        for (int i = 0; i < 15; i++) {
            sbu.append(letter.charAt(rand.nextInt(letter.length())));
        }
        return sbu.toString();
    }
}
